package org.restaurantexample.ws;

import java.util.List;

import org.restaurantexample.www.restaurantservice.GetAllRestaurantData;
import org.restaurantexample.www.restaurantservice.GetAllRestaurantDataFault;
import org.restaurantexample.www.restaurantservice.GetAllRestaurantDataResponse;
import org.restaurantexample.www.restaurantservice.GetRestaurantInfoByCusine;
import org.restaurantexample.www.restaurantservice.GetRestaurantInfoByCusineFault;
import org.restaurantexample.www.restaurantservice.GetRestaurantInfoByCusineResponse;
import org.restaurantexample.www.restaurantservice.GetRestaurantInfoByName;
import org.restaurantexample.www.restaurantservice.GetRestaurantInfoByNameFault;
import org.restaurantexample.www.restaurantservice.GetRestaurantInfoByNameResponse;
import org.restaurantexample.www.restaurantservice.GetRestaurantInfoByRating;
import org.restaurantexample.www.restaurantservice.GetRestaurantInfoByRatingFault;
import org.restaurantexample.www.restaurantservice.GetRestaurantInfoByRatingResponse;
import org.restaurantexample.www.restaurantservice.Restaurant;
import org.restaurantexample.www.restaurantservice.RestaurantList;
import org.restaurantexample.www.restaurantservice.ServiceUnavailableException;



public class RestaurantLogic implements RestaurantServiceSkeletonInterface
{

	@Override
	public GetRestaurantInfoByCusineResponse getRestaurantInfoByCusine(
			GetRestaurantInfoByCusine getRestaurantInfoByCusine)
			throws GetRestaurantInfoByCusineFaultException {
		try
		{
			RestaurantList restaurantData;
			GetRestaurantInfoByCusineResponse response = new GetRestaurantInfoByCusineResponse();
			RestaurantDAO restaurantDAO = new RestaurantDAO();
			restaurantData = restaurantDAO.getRestaurantByCusine(getRestaurantInfoByCusine.getIn());
			response.setOut(restaurantData);
			return response;			
		}
		catch(Exception e)
		{
			GetRestaurantInfoByCusineFault cusineFault = new GetRestaurantInfoByCusineFault();
			cusineFault.setGetRestaurantInfoByCusineFault(ErrorMessage.ServiceUnavailableError);
			GetRestaurantInfoByCusineFaultException error = new GetRestaurantInfoByCusineFaultException();
			error.setFaultMessage(cusineFault);
			throw error;
		}
	}

	@Override
	public GetRestaurantInfoByNameResponse getRestaurantInfoByName(
			GetRestaurantInfoByName getRestaurantInfoByName)
			throws GetRestaurantInfoByNameFaultException {
		try
		{
			Restaurant restaurantData;
			GetRestaurantInfoByNameResponse response = new GetRestaurantInfoByNameResponse();
			RestaurantDAO restaurantDAO = new RestaurantDAO();
			restaurantData = restaurantDAO.getRestaurantByName(getRestaurantInfoByName.getIn());
			response.setOut(restaurantData);
			return response;
		}
		catch(Exception e)
		{
			GetRestaurantInfoByNameFault nameFault = new GetRestaurantInfoByNameFault();
			nameFault.setGetRestaurantInfoByNameFault(ErrorMessage.ServiceUnavailableError);
			GetRestaurantInfoByNameFaultException error = new GetRestaurantInfoByNameFaultException();
			error.setFaultMessage(nameFault);
			throw error;	
		}
		
	}

	@Override
	public GetRestaurantInfoByRatingResponse getRestaurantInfoByRating(
			GetRestaurantInfoByRating getRestaurantInfoByRating)
			throws GetRestaurantInfoByRatingFaultException {
		try
		{
			RestaurantList restaurantData;
			GetRestaurantInfoByRatingResponse response = new GetRestaurantInfoByRatingResponse();
			RestaurantDAO restaurantDAO = new RestaurantDAO();
			restaurantData = restaurantDAO.getRestaurantByRating(getRestaurantInfoByRating.getIn());
			response.setOut(restaurantData);
			return response;
		}
		catch(Exception e)
		{
			GetRestaurantInfoByRatingFault ratingFault = new GetRestaurantInfoByRatingFault();
			ratingFault.setGetRestaurantInfoByRatingFault(ErrorMessage.ServiceUnavailableError);
			GetRestaurantInfoByRatingFaultException error = new GetRestaurantInfoByRatingFaultException();
			error.setFaultMessage(ratingFault);
			throw error;	
		}
	}

	@Override
	public GetAllRestaurantDataResponse getAllRestaurantData(
			GetAllRestaurantData getAllRestaurantData)
			throws GetAllRestaurantDataFaultException {
		try
		{
			RestaurantList restaurantData;
			GetAllRestaurantDataResponse response = new GetAllRestaurantDataResponse();
			RestaurantDAO restaurantDAO = new RestaurantDAO();
			restaurantData = restaurantDAO.getAllRestaurantData();
			response.setOut(restaurantData);
			return response;
		}
		catch(Exception e)
		{
			GetAllRestaurantDataFault ratingFault = new GetAllRestaurantDataFault();
			ratingFault.setGetAllRestaurantDataFault(ErrorMessage.ServiceUnavailableError);
			GetAllRestaurantDataFaultException error = new GetAllRestaurantDataFaultException();
			error.setFaultMessage(ratingFault);
			throw error;	
		}
	}
	

}
